﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NS_DBOP;

public partial class Flow_FlowM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataSet ds = new DBoperate().ExecuteQuery("select * from FlowType",0,0,"table1");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.drpType.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
            }
            this.drpType.Items.Insert(0, "请选择");
            Bind();
        }
    }

    public void Bind()
    {
        DataSet ds = new DBoperate().ExecuteQuery("select * from Flow where IsFix=1", 0, 0, "tabflow");
        this.GridView1.DataSource = ds.Tables[0];
        this.GridView1.DataBind();
        this.lblCount.Text = "共有"+ds.Tables[0].Rows.Count+"条记录";
    }
    protected void btnFind_Click(object sender, EventArgs e)
    {
        if (this.drpType.SelectedItem.Text == "请选择")
        {
            Bind();
        }
        else
        {
            string type = this.drpType.SelectedItem.Value.ToString();
            DataSet ds = new DBoperate().ExecuteQuery("select * from Flow where IsFix=1 and TypeID=" + type, 0, 0, "flow");
            this.GridView1.DataSource = ds.Tables[0];
            this.GridView1.DataBind();
            this.lblCount.Text = "共有" + ds.Tables[0].Rows.Count + "条记录";
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id =Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["ID"].ToString());
        int result = new DBoperate().ExecuteUpdate("delete from Flow where ID=" + id);
        if (result > 0)
        {
            Response.Write("<script language=javascript>alert('删除成功！')</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('删除失败！')</script>");
        }
        Bind();
    }
}
